package com.zmn.plat.common.util;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.string.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 类描述：字符串转数组
 *
 * @author yangshuangping
 * @since 2021/07/07 10:07
 */
public class StringToArrayUtil {
    /**
     * 将,逗号分割的字符串转化为List
     *
     * @param strs 字符串
     * @return List<Integer>
     */
    public static List<Integer> convertStrsToList(String strs) {
        return convertStrsToList(strs, GlobalConsts.SPLITER_DEFAULT);
    }

    /**
     * 根据分隔符分割的字符串转化为List
     *
     * @param strs    字符串
     * @param spliter 分隔符
     * @return List<Integer>
     */
    public static List<Integer> convertStrsToList(String strs, String spliter) {
        List<Integer> ids = new ArrayList<>();
        if (StringUtil.isBlank(strs)) {
            return ids;
        }
        String[] tmpIds = strs.split(spliter);
        for (String tmpId : tmpIds) {
            if (StringUtil.isBlank(tmpId.trim())) {
                continue;
            }
            ids.add(Integer.parseInt(tmpId.trim()));
        }
        return ids;
    }
}
